February 23, 2023

Dataset trees

data(trees)
head(trees)
  Girth Height Volume
1   8.3     70   10.3
2   8.6     65   10.3
3   8.8     63   10.2
4  10.5     72   16.4
5  10.7     81   18.8
6  10.8     83   19.7

Dataset trees; Volume vs Girth

model: \(\text{Volume} = \beta_0 + \beta_1\cdot\text{Girth} + \varepsilon; \hspace{1 cm} \varepsilon \sim N(0; \sigma^2)\)
  fitted: \(\text{Volume} = \hat{\beta_0} + \hat{\beta_1} \cdot \text{Girth}\)               \(\hat{\beta_0} = b_0 - \text{estimate of }\beta_0\); \(\hat{\beta_1} = b_1 - \text{estimate of }\beta_1\) <>

Dataset diamond from UsingR

library(UsingR)
library(plotly)
data(diamond)
head(diamond)
  carat price
1  0.17   355
2  0.16   328
3  0.17   350
4  0.18   325
5  0.25   642
6  0.16   342

Dataset mtcars

data(mtcars)
attach(mtcars)
The following object is masked from package:ggplot2:

    mpg
head(mtcars)
                   mpg cyl disp  hp drat    wt  qsec vs am gear carb
Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1

Plot

xax = list(title="Weight",
           titlefont=list(family="Modern Computer Roman"))
yax = list(title="Miles per Gallong",
           titlefont=list(family="Modern Computer Roman"))

New Plot

plot_ly(mtcars, x=wt, y=mpg, type="scatter", mode="markers", col=disp) %>%
  layout(xaxis=xax, yaxis=yax)
Warning: 'scatter' objects don't have these attributes: 'col'
Valid attributes include:
'cliponaxis', 'connectgaps', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'fill', 'fillcolor', 'fillpattern', 'groupnorm', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hoveron', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'legendgroup', 'legendgrouptitle', 'legendrank', 'line', 'marker', 'meta', 'metasrc', 'mode', 'name', 'opacity', 'orientation', 'selected', 'selectedpoints', 'showlegend', 'stackgaps', 'stackgroup', 'stream', 'text', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'

color, cylinder

Warning: `line.width` does not currently support multiple values.

Warning: `line.width` does not currently support multiple values.

Warning: `line.width` does not currently support multiple values.

Equation

\(X \sim N(\mu=30, \sigma^2=5^2); Y \sim N(0,1); Z \sim N(15, 2^2); color = Z\)
\(X, Y, Z - independent\)

set.seed(123)
myX = rnorm(100, mean=30, sd=5)
myY = rnorm(100)
myZ = rnorm(100, mean=15, sd=2)

Scatter Plot

plot_ly(x=myX, y=myY, z=myZ, 
        type="scatter3d", mode="markers",
        color=myZ) %>%
  hide_colorbar()

Surface and Plane Plots

\(f(x,y)=sin(x+1)+y^2\) and \(f(x,y)=0.6x + 8\)

x = seq(-6, 6, 0.5)
y = seq(-2, 2, 0.5)
X = matrix(rep(x, length(y)), nrow=length(y), byrow=T)
Y = matrix(rep(y, length(x)), ncol=length(x), byrow=F)
Z = sin(X+1) + Y^2
Zp = 0.6*X + 0.8
fig = plot_ly(x=X, y=Y, z=Z, showscale=F, width=800, height=550) %>%
  add_surface(contours=list(
    z=list(show=T, 
           usecolormap=T, 
           highlightcolor="#ff0000", 
           project=list(z=T)
           )
    )
    )

Plot

fig = fig %>% layout(list(
  scene=list(camera=list(eye=list(x=1.87, y=0.88, z=-0.6)))
)) %>%
  add_surface(z=Zp)
fig

Latex

\(\cdot, x^2, x^{22}, x_a^{22}, x_{ab}^{22}\) \(\bar{x}, \bar{x}_n, \hat{\Theta}\) \(\alpha, \beta, \gamma, \epsilon, \varepsilon, \phi, \varphi, \chi^2\) \(\displaystyle MSE = {SSE\over n-2} \sum_{i=1}^n (y_i - \hat{y}_i)^2\) \(Hello \hspace{3cm} There\)

DAT 301

Ioslides

Overleaf

  • png
  • jpg
  1. Hello
  2. There
    Are we in trouble now? Why Aye Man

Last plot

plot(mtcars$mpg, mtcars$cyl)
Scatter plot

Scatter plot